<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>品牌列表页</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>
</head>
<body>
	<table id="brand_dg" title="品牌列表" class="easyui-datagrid"
		style="width: 100%; height: 480px"
		url="${param.request.contextPath}/brand/list" toolbar="#brand_toolbar"
		pagination="true" rownumbers="true" fitColumns="true"
		singleSelect="true">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<!--  field字段需要与返回数据的属性名一致 -->
				<th field="brandId" align="center">品牌编号</th>
				<th field="brandName" width="50">品牌名称</th>
				<th field="brandIntroduce" width="50">品牌介绍</th>
				<th field="brandPhoto" formatter="imageFormatter" align="center"
					width="50" height="45">品牌图片</th>
			</tr>
		</thead>
	</table>

	<div id="brand_toolbar">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" onclick="newBrand()">新增</a> <a
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-edit" plain="true" onclick="editBrand()">修改</a> <a
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true" onclick="destroyBrand()">删除</a>
		</div>
		<div>
			&nbsp;品牌名称： <input type="text" id="brandSearch" size="20"
				onkeydown="if(event.keyCode == 13) search()" /> <a
				href="javascript:search()" class="easyui-linkbutton"
				iconCls="icon-search" plain="true">搜索</a>
		</div>
	</div>

	<div id="brand_dlg" class="easyui-dialog"
		style="width: 700px; height: 480px; padding: 10px 20px" closed="true"
		buttons="#brand_dlg-buttons">
		<div class="ftitle">信息管理</div>
		<form id="brand_fm" enctype="multipart/form-data" method="post">
			<div class="fitem">
				<label>品牌名称:</label> <input name="brandName"
					class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>品牌介绍:</label> <input name="brandIntroduce"
					class="easyui-textbox" style="width: 600px; height: 100px">
			</div>
			<div class="fitem">
				<label>品牌图片:</label> <input name="imageFile" class="easyui-filebox">
			</div>

		</form>
	</div>

	<div id="brand_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="save()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#brand_dlg').dialog('close')">取消</a>
	</div>


	<script type="text/javascript">
		function newBrand() {
			$('#brand_dlg').dialog('open').dialog('setTitle', '新增管理');
			$('#brand_fm').form('clear');
			url = '${pageContext.request.contextPath}/brand/add';
		}

		function editBrand() {
			$('#brand_fm').form('clear');
			var row = $('#brand_dg').datagrid('getSelected');
			if (row) {
				$('#brand_dlg').dialog('open').dialog('setTitle', '修改管理');
				$('#brand_fm').form('load', row);
				url = '${pageContext.request.contextPath}/brand/edit?brandId='
						+ row.brandId;
			}
		}

		function save() {
			$('#brand_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Info',
							msg : result.errorMsg
						});
					}

					$('#brand_dlg').dialog('close'); // close the dialog
					$('#brand_dg').datagrid('reload'); // reload the user data
				}
			});
		}

		function destroyBrand() {
			var row = $('#brand_dg').datagrid('getSelected');
			if (row) {
				$.messager
						.confirm(
								'Confirm',
								'确认删除?',
								function(r) {
									if (r) {
										$
												.post(
														'${pageContext.request.contextPath}/brand/delete',
														{
															brandId : row.brandId
														},
														function(result) {
															if (result.success) {
																$('#brand_dg')
																		.datagrid(
																				'reload'); // reload the user data
															} else {
																$.messager
																		.show({ // show error message
																			title : 'Error',
																			msg : result.errorMsg
																		});
															}
														}, 'json');
									}
								});
			}
		}

		function imageFormatter(value, row, index) {
			return "<img  width='45' height='45' src='${pageContext.request.contextPath}/"+value+"'>";
		}

		function search() {
			$("#brand_dg").datagrid('load', {
				"brandName" : $("#brandSearch").val()
			});
			url = '${param.request.contextPath}/brand/list';
		}
	</script>

</body>
</html>